package com.bkhech.config;


import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import com.bkhech.adapter.StorageAdapter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import java.util.Map;

@Configuration
@RefreshScope
@Slf4j
public class StorageConfig {

    @Value("${storage.service.type}")
    private String storageType;

    @Resource
    private Map<String, StorageAdapter> adapterMap;

    @Bean
    @Primary
    @RefreshScope
    public StorageAdapter storageService() {
        log.info("当前适配器为: {}", storageType);
        StorageAdapter storageAdapter = adapterMap.get(storageType);
        if (storageType != null) {
            return storageAdapter;
        } else {
            throw new IllegalArgumentException("未配置存储服务类型");
        }
    }

}
